<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script th:src="@{/static/js/jquery.js}"></script>
    <script th:src="@{/static/js/sweetalert.min-2.1.2.js}"></script>
    <script type="text/javascript">
        $(function () {
            $("#sub").click(function () {
                var u = $("#username").val().trim();
                var p = $("#password").val().trim();
                var p2 = $("#password2").val().trim();
                console.log("(username)---"+u)
                console.log("(password)---"+p)
                console.log("(password2 )---"+p2)
                var b = !u;
                var b1 = !p;
                var b2 =(p2===p);
                console.log("=================================")
                console.log("(!u)---"+b)
                console.log("(!p)---"+b1)
                console.log("(p2===p)---"+b2)
                console.log("=================================")
                if (b){
                    swal("警告", "用户名不能为空", "error").then(function (isOk) {
                    });
                    return;
                }
                if (!p){
                    swal("警告", "密码不能为空", "error").then(function (isOk) {
                    });
                    return;
                }
                if (!(p2===p)){
                    swal("警告", "密码不一致", "error").then(function (isOk) {
                    });
                    return;
                }
                $.ajax({
                    url:"/SSM_01/register",
                    type:"POST",
                    data:{
                        username:u,
                        password:p
                    },
                    success:function (data) {
                        var parse = JSON.parse(data);
                        if (parse.code===1){
                            swal("通知", "注册成功", "success").then(function (isOk) {
                                window.location.href=parse.url;
                            });
                        }else {
                            swal("警告", "密码不一致", "error").then(function (isOk) {});
                        }
                    }

                })
            });
        });
    </script>
</head>
<body>
<label>
    用户名<input id="username" name="username" type="text">
</label>
<br>
<label>
    密码<input id="password" name="password" type="password">
</label>
<br>
<label>
    确认密码<input id="password2" type="password">
</label>
<br>
<button id="sub">提交</button>
</body>
</html>